//
//  SYJStatusesModel.swift
//  weibo
//
//  Created by 孙英建 on 16/4/20.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class SYJStatusesModel: NSObject {

    
    /// 微博创建时间
    var created_at: String?
    /// 微博ID
    var id: Int64 = 0
    /// 微博信息内容
    var text: String?
    /// 微博来源
    var source: String?
    /// 用户模型
    var user: SYJUserInfoModel?

    
    // 原创微博配图
    var pic_urls:[SYJPictureInfoModel]?
    
    // 转发微博的(如果没有转发微博 服务器会返回一个nil)
    var retweeted_status:SYJStatusesModel?

    // 转发数
    var reposts_count: Int = 0
    // 评论数
    var comments_count: Int = 0
    // 表态数
    var attitudes_count: Int = 0
    
    init(dict: [String: AnyObject]) {
        super.init()
        
        setValuesForKeysWithDictionary(dict)
    }
    
    // 因为用户里边还是字典所以需要再次手动字典转模型
    override func setValue(value: AnyObject?, forKey key: String) {
        
        if key == "user"{
           
            if let userValue = value as? [String: AnyObject]{
                
                let us = SYJUserInfoModel(dict: userValue)
                user = us 
            }
            // 微博配图
        }else if key == "pic_urls" {
                
                var tempArr: [SYJPictureInfoModel] = [SYJPictureInfoModel]()
                if let arr = value as? [[String: AnyObject]]{
                    for dict in arr {
                        let dm = SYJPictureInfoModel(dict: dict)
                        tempArr.append(dm)
                    }
                    pic_urls = tempArr
                }
            // 转发微博
        }else if key == "retweeted_status" {
            if let v = value as? [String:AnyObject]{
                let s = SYJStatusesModel(dict: v)
                retweeted_status = s
            }
        }else{
            super.setValue(value, forKey: key)
        }
        
            
        
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    
}










